#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  string s;
  int n;
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> s;
    int cnt = -INF;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        if (cnt >= 0 && cnt < 2) {
          ans += 2 - cnt;
        }
        cnt = 0;
      } else {
        cnt++;
      }
    }
    cout << ans << endl;
  }
}
